package com.wellsoft.mobileoa.utils.action;

import com.wellsoft.mobileoa.utils.BaseAction;
import com.wellsoft.mobileoa.utils.BaseView;
import com.wellsoft.mobileoa.utils.BaseWidget;
import com.wellsoft.mobileoa.utils.SystemConfig;
import com.wellsoft.mobileoa.wsmodel.WSOA_Action;
import com.wellsoft.mobileoa.wsmodel.WSOA_ActionData;
import com.wmobile.utils.PopListDialog;
import com.wmobile.utils.PopReasonDialog;
import com.wmobile.utils.ServiceResponse;

public class InputReasonAction extends BaseAction {

	public InputReasonAction(WSOA_Action action, BaseView baseView) {
		this.action = action;
		this.baseView = baseView;
	}

	@Override
	public ServiceResponse excuteAction() {
		PopReasonDialog popDialog;
		BaseWidget sender;

		sender = baseView.getWidgetById(action.getPname());
		if (!SystemConfig.stringIsNullOrEmpty(action.getChangeNotedite())
				&& action.getChangeNotedite().equals("1")) {
			if (sender.hasEdited) {
				return new ServiceResponse(true);
			}
		}
		String senderValue = "";
		if (sender != null && sender.getRawValue() != null
				&& !sender.getRawValue().toUpperCase().equals("FULL")) {
			senderValue = sender.getRawValue();
		}
		popDialog = new PopReasonDialog<WSOA_ActionData>(
				baseView.getBaseActivity(), action.getPageTitle().getMessage(), senderValue);
		if (popDialog.showDialog() != PopListDialog.DialogResultOK) {
			return new ServiceResponse(false);
		}
		if(SystemConfig.stringIsNullOrEmpty(popDialog.getOpinion())){
			return new ServiceResponse(false);
		}else{
			sender.setValue(popDialog.getOpinion());
			return new ServiceResponse(true);
		}
	}

}
